﻿<template>
    <div class="table">
        <div  class="divSearch">
            <Row>
                <Col v-show="userinfo.AreaCode=='530000000000'">
                    <label class="searchLabel">所属地区:</label>
                    <!-- <Cascader :data="AreaList" change-on-select @on-change='SearchCascaderChange'  class="searchInput"></Cascader>-->
                    <Select v-model="searchModel.AreaCode"  placeholder="请选择..."  @on-change="getStatsData()" class="searchInput">
                        <Option :value="userinfo.AreaCode" v-if="userinfo.AreaCode=='530000000000'">全&nbsp;&nbsp;省</Option>
                        <Option :value="userinfo.AreaCode" v-else>全市/州</Option>
                        <Option :value="item.value" v-for="item in AreaList" :key="item.value">{{item.label}}</Option>
                    </Select>
                </Col>
            <!--搜索框-->
                <Col>
                    <label class="searchLabel">填报年度:</label>
                    <Select v-model="searchModel.FillInYear" placeholder="请选择..." :label-in-value="true" clearable class="searchInput" @on-change="getStatsData()">
                        <Option :value="item.DictText" v-for="item in CreateYearList" :key="item.DictValue">{{item.DictText}}</Option>
                    </Select>
                </Col>
                <Col>
                    <label class="searchLabel">品种类别选择:</label>
                    <Select v-model="searchModel.itemText"  placeholder="请选择..." :label-in-value="true" clearable class="searchInput" style="width: 200px;" @on-change="getStatsData()">
                        <Option value="">全部</Option>
                        <Option :value="item.DictValue" v-for="item in CultivarList" :key="item.DictValue">{{item.DictText}}</Option>
                    </Select>
                </Col>
                <Col >
                    <Button type="primary" @click="DataExport()"  class="searchRight" icon="log-out" >数据导出</Button>
                    <RadioGroup v-model="CheckButton" @on-change="changeButton" type="button" class="searchRight" >
                        <Radio label="listShow" title="列表">列表</Radio>
                        <Radio label="barShow" title="饼图">柱状图</Radio>                                                                                  
                    </RadioGroup> 
                </Col>
            </Row>
        </div>
        <Row v-show="listShow">
            <table class="ContentTable">
                <caption>
                    <div><span class="tableNum">表12——{{searchModel.FillInYear}}&nbsp;{{userinfo.AreaCode|omgAreaName}}&nbsp;全年蚕种生产情况调查表</span>
                        <span class="tip">单位：张</span>
                    </div>
                </caption>
                <thead>
                    <tr>
                        <th rowspan="2" style="width:50px;">序号</th>
                        <!-- <th rowspan="2" style="width:80px;">年份</th> -->
                        <th rowspan="2">制种单位</th>
                        <th rowspan="2">品种</th>
                        <th colspan="4">制种量（张）</th>
                        <th rowspan="2">其中：越年种(张)</th>
                        <th rowspan="2">备注</th>
                    </tr>
                    <tr>
                        <th>合计</th>
                        <th>春制种</th>
                        <th>夏制种</th>
                        <th>秋制种</th>
                    </tr>
                    <tr v-if="datas.length>0">
                        <!-- <td style="width:80px;">{{datas[0].FillYear}}</td> -->
                        <td style="width:50px;">{{1}}</td>
                        <td >合计</td>
                        <td v-show="searchModel.itemText==''">全部</td>
                        <td v-show="searchModel.itemText!=''">{{searchModel.itemText|omgConvDict('CSCultivar')}}</td>
                        <td >{{datas[0].SeedProducTotal|integer|formatCurrency}}</td>
                        <td >{{datas[0].SeedProducSpring|integer|formatCurrency}}</td>
                        <td >{{datas[0].SeedProducSummer|integer|formatCurrency}}</td>
                        <td >{{datas[0].SeedProducAutumn|integer|formatCurrency}}</td>
                        <td >{{datas[0].OverYearSpec|integer|formatCurrency}}</td>
                        <td >{{datas[0].Remark}}</td>
                    </tr>
                </thead>
                <tbody v-if="newDatas.length>0">
                    <tr v-for="(item,index) in newDatas" :key="item.FillYear">
                        <td style="width:50px;">{{index+2}}</td>
                        <!-- <td style="width:80px;">{{item.FillYear}}</td> -->
                        <td >{{item.SeedUnitName}}</td>
                        <td v-show="searchModel.itemText==''">全部</td>
                        <td v-show="searchModel.itemText!=''">{{searchModel.itemText|omgConvDict('CSCultivar')}}</td>
                        <td >{{item.SeedProducTotal|integer|formatCurrency}}</td>
                        <td >{{item.SeedProducSpring|integer|formatCurrency}}</td>
                        <td >{{item.SeedProducSummer|integer|formatCurrency}}</td>
                        <td >{{item.SeedProducAutumn|integer|formatCurrency}}</td>
                        <td >{{item.OverYearSpec|integer|formatCurrency}}</td>
                        <td >{{item.Remark}}</td>
                    </tr>
                </tbody>
            </table>
        </Row>
         <Row v-show="barShow">
            <!--饼图-->
            <div  id="divBar" style="margin-right:10px;border:1px solid #D7DDE4; ">柱状图</div>
        </Row>
    </div>
</template>
<script>
export default {
    data() {
        return {
            self: this,
            CreateYearList: this.GetGroupDict("ReportYear"), //年度
            CurrentYear: this.GetCurrentYear(),//当前年度
            AreaList: this.SearchAreaList(this.GetlocaStorage("CSuserinfo").AreaCode),
            CurrentAreaName:'',
            userinfo: this.GetlocaStorage("CSuserinfo"),//获取当前用户信息
            CultivarList: this.GetGroupDict("CSCultivar"),
            CheckButton:'listShow',
            datas:[],//列表数据
            newDatas:[],//去除合计的数据集合
            //柱状图数据
            echartsItem:['全年制种量','春制种量','夏制种量','秋制种量'],
            XData:[],
            barList:[],
            SeedProducTotalData:[],
            SeedProducSpringData:[],//销售蚕种量(杂交种)
            SeedProducSummerData:[],//成本
            SeedProducAutumnData:[],//利润
            //查询模型：根据需求删除不不要查询条件
            //蔬菜生产情况表代码
            searchModel: {
                Id: '',
                ReportCode: 'MulEggsProducStatist',
                FillInYear: '',
                TimesType: '',
                AreaCode: this.GetlocaStorage("CSuserinfo").AreaCode,
                itemText:'',
                PageNumber: 1,
                PageSize: 20,
                Status: '4',
                Opinion: ''
            },
            clientHeight: window.innerHeight - 250,//表格默认高度
            listShow:true,//列表显示控制器
            barShow:false,//饼图显示控制器
        }
    },
    //高度计算
     mounted() {
        //table高度计算方法
        const that = this;
        window.onresize = () => {
            return (() => {
                that.clientHeight = window.innerHeight - 250;
            })()
        };
    },
    //方法
    methods: {  
        //展示切换
        changeButton:function(n){
            if(n=="listShow")
            {
                this.listShow=true;//显示列表
                this.barShow=false;
            }
            else if(n=="barShow")
            {
                this.listShow=false;
                this.barShow=true;//显示柱状图
            }
            else{
                 this.listShow=true;//默认显示列表
                 this.barShow=false;
            }
        },
        //获取当前页码
        getPageNumber(pageIndex) {
            this.searchModel.PageNumber = pageIndex;
            this.getStatsData();
        },
        //获取当前分页大小
        getPageSize(pageSize) {
            this.searchModel.PageSize = pageSize;
            this.getStatsData();
        },
        //获取地区统计数据
        getStatsData(){
            var self = this;
            if (self.searchModel.FillInYear != null && self.searchModel.FillInYear != '') {
                self.searchModel.FillInYear = self.searchModel.FillInYear;//获取当前系统年份
            } 
            else {
                self.searchModel.FillInYear = self.CurrentYear + '年'; //获取填报年度-----数据字典值
            }
            self.datas=[];
            self.newDatas = [];
            self.XData=[],
            self.barList=[],
            self.SeedProducTotalData=[],//合计
            self.SeedProducSpringData=[],//春
            self.SeedProducSummerData=[],//夏
            self.SeedProducAutumnData=[];//秋
            self.$http.post('MulEggsProducStatist/PostStatsList', self.searchModel).then(function (res) {
                if (res.data.status === 1) {
                     if (res.data.model!=null&&res.data.model.length > 0) {
                        self.datas=res.data.model;//列表赋值
                        var len=res.data.model.length
                        for(var i=1;i<len;i++){
                            self.newDatas[i-1] = res.data.model[i];
                            self.XData.push(res.data.model[i].SeedUnitName);
                            self.SeedProducTotalData.push(res.data.model[i].SeedProducTotal);
                            self.SeedProducSpringData.push(res.data.model[i].SeedProducSpring);
                            self.SeedProducSummerData.push(res.data.model[i].SeedProducSummer);
                            self.SeedProducAutumnData.push(res.data.model[i].SeedProducAutumn);
                        }
                        self.barList.push(self.SeedProducTotalData,self.SeedProducSpringData,self.SeedProducSummerData,self.SeedProducAutumnData);
                    }
                     self.showEcharts();
                }
                else {
                    self.$Modal.error({
                    title: '提示信息',
                    content: res.data.message
                    });
                }
            });
        },
        DataExport(){
            //导出
           var self = this;
            var user = self.GetlocaStorage("CSuserinfo");
            if (self.searchModel.FillInYear != null && self.searchModel.FillInYear != '') {
                self.searchModel.FillInYear = self.searchModel.FillInYear;//获取当前系统年份
            } 
            else {
                self.searchModel.FillInYear = self.CurrentYear + '年'; //获取填报年度-----数据字典值
            }
            window.open(this.$http.defaults.baseURL + "MulEggsProducStatist/GetStatsExcelData?FillInYear=" + self.searchModel.FillInYear+"&&AreaCode=" + self.searchModel.AreaCode+"&&Status=" + self.searchModel.Status+"&&itemText=" + self.searchModel.itemText);
        },
        //展示柱状图代码
        showEcharts(){
            //************************显示柱状图
            var self=this;
            var containerBar=document.getElementById('divBar');
            var containerTable=document.getElementsByClassName('ivu-col ivu-col-span-4');
            // //用于使chart自适应高度和宽度,通过窗体高宽计算容器高宽
            var resizeContainerBar = function () {
                containerBar.style.width = (window.innerWidth- containerTable[0].clientWidth-40)+'px';
                containerBar.style.height = (window.innerHeight-240)+'px';
            };
            //设置容器高宽
            resizeContainerBar();
            var myBar = myEcharts.init(containerBar, 'shine');
            var BarName='表12——'+self.searchModel.FillInYear+self.CurrentAreaName+'全年蚕种生产情况柱状统计图(单位:万张、万元)';
            var optionBar = self.GetBarOption(BarName,self.XData,self.echartsItem,self.barList,'bar');
            console.log(optionBar)
            myBar.setOption(optionBar);
            //用于使chart自适应高度和宽度
            window.onresize = function () {
                //重置容器高宽
                resizeContainerBar();
                myBar.resize();
            };
        }
    },
    //创建Vue页面方法
    created: function () { 
        this.getStatsData();      
    },
    watch: {
        //需要监听的在此处新增监听对象
    }
}
</script>
<style scoped src="../../styles/stats.css"></style>
